<?php

require_once 'SDOVipSocket.php';

/*
 * SDOApiVipService
 * 封装SDO Vip socket接口
 * @author Wolfhead (Mei xueting)
 */
class SDOApiVipService {
    
    /*
     * 查询用户信息
     * @param int $appId 应用ID
     *
     * @param Array $fields 字段域 
     *          VipRank VIP等级
     *          VipValidDate    VIP有效期  
     *          VipPhone    绑定的电话号码 其他应用使用
     *          VipNext 距离下一等级的距离   其他应用使用 
     * @param long long $uid 用户ID
     * @return Array 由 $fields 为 key 的  key->value数组
     */
    static public function QueryUserInfo($uid, $fields, $appId = '11')
    {
        $apiName = "vipservice.QuerryUserInfo";
        
        $param = array();
        
        $param['AppId'] = $appId;
        $param['SndaId'] = $uid;
        
        $nameMap = array_flip(SDOVipSocket::$nameMap);
        
        $nameField = array();
        
        foreach ($fields as $f)
        {
            if (isset($nameMap[$f]))
            {
                $nameField[] = $nameMap[$f];
            }
        }
        
        $param['FieldKey'] = $nameField;
        
        $result = self::send($apiName, $param);
        if (is_array($result))
        {
            foreach ($result as $key => $value)
            {
                //$result[$key] = mb_convert_encoding($value, "UTF-8", "ASCII");
            }
        }
        
        return $result;
    }
    
    static protected function send($apiName, $param)
    {
        return SDOVipSocket::send($apiName, $param);
    }
}